#include <iostream>
#include <string>

// 字符串的操作 拷贝 拼接 查找 替换 增删改查

using namespace std;

int main(int argc, char const *argv[])
{
    // 字符串拼接
    string s1 = "hello";
    string s2 = "world";
    string s3 = "!!!!!";
    string s4 = s1 + s2 + s3;
    s4.append("!!!!!");

    cout << "s1 = " << s1 << endl;
    cout << "s2 = " << s2 << endl;
    cout << "s3 = " << s3 << endl;
    cout << "s4 = " << s4 << endl;

    //strcmp
    s2 = s1;
    if (s1 == s2)
    {
        cout << "相等" << endl;
    }
    else
    {
        cout << "不相等" << endl;
    }

    // 查找 替换
    int pos = s1.find("llo");
    cout << "pos = " << pos << endl;

    if (pos == s1.npos)
    {
        cout << "没找到" << endl;
    }

    // 替换
    s1.replace(pos,3,"c++");
    cout << s1 << endl;

    // 请求长度
    int len = s1.length();
    cout << "len = " << len << endl;

    // 从字符串中读取
    char c_str[128] = "zhangsan";
    char ch = c_str[1];
    cout << "ch = " << ch << endl;

    ch = s1[1];
    cout << "ch = " << ch << endl;

    //at
    ch = 'A';
    ch = s1.at(1);
    cout << "ch = " << ch << endl;

    // 插入 和 删除
    s1.insert(1,"刘");
    cout << "s1 = " << s1 << endl;

    s1.erase(1,3);
    cout << "s1 = " << s1 << endl;

    // 清空
    s1.clear();
    cout << "s1 = " << s1 << endl;
    
    return 0;
}
